<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>

    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <!--  -->
      <div class="x-pro-list">
        <div class="x-pro-top">今日值班问题点</div>
        <div class="x-pro-desc" v-for="(item,index) in todaypro">
          <div class="x-pmo-de">问题{{index+1}} : {{item.content}}</div>
        </div>
      </div>
      <!--  -->
      <div class="x-pro-list" v-for="(item,index) in prodata" :key="item.key">
        <div class="x-pro-top">提案{{index+1}}</div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">提案内容:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="item.question" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">分析成因:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="item.reason" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">改善提议:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="item.improve" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-remove" @click="removeentrywork(index)" v-show="!isfromindex">删除</div>
      </div>
      <!--  -->
      <div class="x-pro-addbox" @click="goonentrywork"  v-show="!isfromindex"><span class="x-pro-addicon"></span>添加提案</div>
      <!--  -->
      <div class="x-pro-gobtn" @click="isok" v-show="!isfromindex">提交</div>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          todaypro:'',
          isfromindex:false,
          prodata:[{
            'question':'',
            'reason':'',
            'improve':'',
            'index':0,
          }],
          entryworkindex:0,

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.getshow()

      },
      methods: {
        //
        getshow:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/getBmp',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:''
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                // for(var i=0;i<ret.data.check.length;i++){
                //   console.log(ret.data.check[i].content);
                //   that.todaypro += ret.data.check[i].content;
                // }
                that.todaypro = ret.data.check;
                that.prodata = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //提交
        isok:function(){
          var that = this;
          api.ajax({
            url:baseurl+'api/duty/setBmp',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:'',
                proposal_json:that.prodata

              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.alert({
                    title: '提交成功',
                    msg: '',
                }, function(ret, err) {

                });

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //继续添加
        goonentrywork:function(){
          var that = this;
          that.entryworkindex++
          that.prodata.push({
            'question':'',
            'reason':'',
            'improve':'',
            'index':that.entryworkindex,
          });
        },
        //删除
        removeentrywork:function(index){
          let that = this;
          var nowin = index;
          console.log(JSON.stringify(that.prodata));
          api.confirm({
            title: '操作提示',
            msg: '确定要删除吗？',
            buttons: ['确定','取消']
          }, function(ret, err) {
            var index = ret.buttonIndex;
            if(index == 1){
              //删除
              that.prodata.splice(nowin,1);//删除全部数组中对应的值
              console.log(JSON.stringify(that.prodata));
            }
          });
        },
      }
    })
	}


	</script>
</body>
</html>
